/*
 * @Author: aggfb 714740235@qq.com
 * @Date: 2024-04-22 21:39:52
 * @LastEditors: aggfb 714740235@qq.com
 * @LastEditTime: 2024-06-08 16:04:20
 * @FilePath: \label_rack_control\firmware\model\fiber_optic\fiber_optic.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "apm32f10x_conf.h"
#include "fiber_optic.h"
#include "motor_ctrl.h"

static fiber_optic_t fiber_optic = {
    .count = 0,
    .flag_trig = 0,
};

/**
*   外部调用设备接口 
*/
fiber_optic_t* fiber_optic_dev(void)
{
    return &fiber_optic;
}

/**
 * 清楚设备计数值
*/
void fiber_optic_clear_count(void)
{
    fiber_optic.count = 0;
}

/**
 * 检测到传感器中断
*/
void TMR2_IRQHandler(void)
{
    if (TMR_ReadIntFlag(TMR2, TMR_INT_CC1) == SET)
    {
        TMR_ClearIntFlag(TMR2, TMR_INT_CC1);
        /* 检测到物料后,执行offset偏移量 */
        if (BSP_GPIO_GET_SENSER == BIT_RESET)
        {
            /* 检测到物料标志  */
            fiber_optic.flag_trig = 1;
            fiber_optic.count++;
        }
    }
}

